<?php

class WareHouseProduct extends DataObject {

    static $db = array(
        'Title' => 'Varchar(255)',
        'Code' => 'Varchar(255)',
        'Quantity' => 'Int',
        'Unit' => 'Varchar(255)',
        'SortOrder' => 'Int'
    );

    static $has_one = array(
        'Image' => 'Image'
    );

    static $has_many = array(
//        'EProductImages' => 'EProductImage',
    );

    static $many_many = array(
//        'ECategories' => 'ECategory'
    );

//    static $searchable_fields = array(
//        'Title', 'UrlSegment', 'Publish'
//    );

//    static $defaults = array('View' => 0, 'Publish' => true);
    static $singular_name = 'Product';

    public static $default_sort = 'SortOrder';

    function getCMSFields() {
        return new FieldList(array(
            new UploadField('Image', 'Image'),
            new TextField('Title', 'Title'),
            new HtmlEditorField('Code', 'Code'),
            new HtmlEditorField('Quantity', 'Quantity'),
            new HtmlEditorField('Unit', 'Unit'),
            new HiddenField('SortOrder')
        ));
    }

    static $summary_fields = array(
        'thumb' => 'Image',
        'Title' => 'Title',
        'Code' => 'Code',
        'Quantity' => 'Quantity',
        'Unit' => 'Unit'
    );

    function thumb() {
        return $this->ImageID != 0 ? $this->Image()->CMSThumbnail() : 'no-image';
    }
}